﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EasyCocos2D
{
    public class CCLabelTTF : CCGameObject
    {
        private string cctext;
        public string Text
        {
            get { return cctext; }
            set { cctext = value; }
        }

        private Font font;
        public Font Font
        {
            get { return font; }
            set { font = value; }
        }

        private Color color;
        public Color BackColor
        {
            get { return color; }
            set { color = value; }
        }

        private Size size;
        public Size Size
        {
            get { return size; }
            set { size = value; }
        }

        public CCLabelTTF(string text) : base()
        {
            Text = text;
            Font = new Font("Meiryo UI", 10F);
            BackColor = Color.Black;
            Size = new Size((int)Font.Size*Text.Length, Font.Height);
        }

        public override string serialineH()
        {
            string s = "";
            s += String.Format("\t\tCCLabelTTF *{0};\n", Name);
            return s;
        }

        public override string serialineCPP()
        {
            string s = "";
            s += String.Format("\t{0} = CCLabelTTF::create(\"{1}\", \"{2}\", {3});\n\t{0}->setColor(ccc3({4}, {5}, {6}));\n\t{0}->setPosition(ccp({7}, {8}));\n", Name, Text, Font.Name, Font.Size, BackColor.A, BackColor.B, BackColor.G, Position.X, Position.Y);
            return s;
        }

        public override bool getObject(System.Drawing.Point p)
        {
            if (Position.X < p.X && p.X < Position.X + Size.Width &&
                Position.Y < p.Y && p.Y < Position.Y + Size.Height)
            {
                return true;
            }

            return false;
        }

        public override void Draw(System.Drawing.Graphics g)
        {
            Size = new Size((int)Font.Size*Text.Length, Font.Height);
            Brush b = new SolidBrush(BackColor);

            g.DrawString(Text, Font, b, Position);
        }
    }
}
